package com.bestow.loan.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestow.common.annotation.Log;
import com.bestow.common.core.controller.BaseController;
import com.bestow.common.core.domain.AjaxResult;
import com.bestow.common.enums.BusinessType;
import com.bestow.loan.domain.InvFinanceProducts;
import com.bestow.loan.service.IInvFinanceProductsService;
import com.bestow.common.utils.poi.ExcelUtil;
import com.bestow.common.core.page.TableDataInfo;

/**
 * 理财产品定义Controller
 * 
 * @author liliu
 * @date 2022-09-04
 */
@RestController
@RequestMapping("/loan/financeProducts")
public class InvFinanceProductsController extends BaseController
{
    @Autowired
    private IInvFinanceProductsService invFinanceProductsService;

    /**
     * 查询理财产品定义列表
     */
    @PreAuthorize("@ss.hasPermi('loan:financeProducts:list')")
    @GetMapping("/list")
    public TableDataInfo list(InvFinanceProducts invFinanceProducts)
    {
        startPage();
        List<InvFinanceProducts> list = invFinanceProductsService.selectInvFinanceProductsList(invFinanceProducts);
        return getDataTable(list);
    }

    /**
     * 导出理财产品定义列表
     */
    @PreAuthorize("@ss.hasPermi('loan:financeProducts:export')")
    @Log(title = "理财产品定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InvFinanceProducts invFinanceProducts)
    {
        List<InvFinanceProducts> list = invFinanceProductsService.selectInvFinanceProductsList(invFinanceProducts);
        ExcelUtil<InvFinanceProducts> util = new ExcelUtil<InvFinanceProducts>(InvFinanceProducts.class);
        util.exportExcel(response, list, "理财产品定义数据");
    }

    /**
     * 获取理财产品定义详细信息
     */
    @PreAuthorize("@ss.hasPermi('loan:financeProducts:query')")
    @GetMapping(value = "/{financeProductsId}")
    public AjaxResult getInfo(@PathVariable("financeProductsId") Long financeProductsId)
    {
        return AjaxResult.success(invFinanceProductsService.selectInvFinanceProductsByFinanceProductsId(financeProductsId));
    }

    /**
     * 新增理财产品定义
     */
    @PreAuthorize("@ss.hasPermi('loan:financeProducts:add')")
    @Log(title = "理财产品定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InvFinanceProducts invFinanceProducts)
    {
        return toAjax(invFinanceProductsService.insertInvFinanceProducts(invFinanceProducts));
    }

    /**
     * 修改理财产品定义
     */
    @PreAuthorize("@ss.hasPermi('loan:financeProducts:edit')")
    @Log(title = "理财产品定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InvFinanceProducts invFinanceProducts)
    {
        return toAjax(invFinanceProductsService.updateInvFinanceProducts(invFinanceProducts));
    }

    /**
     * 删除理财产品定义
     */
    @PreAuthorize("@ss.hasPermi('loan:financeProducts:remove')")
    @Log(title = "理财产品定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{financeProductsIds}")
    public AjaxResult remove(@PathVariable Long[] financeProductsIds)
    {
        return toAjax(invFinanceProductsService.deleteInvFinanceProductsByFinanceProductsIds(financeProductsIds));
    }
}
